<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>项目管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				},
				rules:{
					name:{
						remote: {
						    url: $("#ctx").val()+"/pro/project/getByName",     //后台处理程序
						    type: "post",               //数据发送方式
						    dataType: "json",           //接受数据格式   
						    data: {                     //要传递的数据
						        name: function() {
						            return $("#name").val();
						        },
						        id: function(){
						        	return $("#id").val();
						        }
						    }
						}
					}
				},
				messages:{
					name:{
						remote:"该项目名称已存在！"
					}
				}
			});
		});
		function submitForm(){                                      //子窗体页面的保存数据方法 通过ajax
			var flag = false;
            if($("#inputForm").valid()){
                var url = "${ctx}/pro/project/save";
                $.ajax({
                    type: 'POST',
                    url : url,
                    async:false,
                    data: $('#inputForm').serialize(),             //获取表单数据
                    success : function(data) {
                    	    flag = true;
                            alert("保存成功");
                            parent.$('#btn').click();
                            parent.$.jBox.close(true);
                            
                            /* window.parent.page();                                     //调用父窗体方法，当关闭子窗体刷新父窗体
                            window.parent.window.jBox.close(); */            //关闭子窗体
                    },
                    error : function(data){
                    	alertx("无权限");
                    }
                });
            }
            return flag;
        }
	</script>
</head>
<body>
	<%-- <ul class="nav nav-tabs">
		<li><a href="${ctx}/pro/project/">项目列表</a></li>
		<li class="active"><a href="${ctx}/pro/project/form?id=${project.id}">项目<shiro:hasAnyPermissions name="pro:project:edit,pro:project:create">${not empty project.id?'修改':'添加'}</shiro:hasAnyPermissions><shiro:lacksPermission name="pro:project:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/> --%>
	<form:form id="inputForm" modelAttribute="project" action="${ctx}/pro/project/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<input type="hidden" id="ctx" value="${ctx}"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">项目名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">负责人：</label>
			<div class="controls">
				<sys:treeselect id="manager" name="manager.id" value="${project.manager.id}" labelName="manager.name" labelValue="${project.manager.name}"
					title="用户" url="/sys/office/treeData?type=3" cssClass="required" allowClear="true" notAllowSelectParent="true"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">项目起始时间：</label>
			<div class="controls">
				<input name="startTime" id="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${project.startTime}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,minDate:'%y-%M-%d',maxDate:'#F{$dp.$D(\'endTime\')}'});"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">项目结束时间：</label>
			<div class="controls">
				<input name="endTime" type="text" id="endTime" readonly="readonly" maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${project.endTime}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,minDate:'#F{$dp.$D(\'startTime\')}'});"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">项目状态：</label>
			<div class="controls">
				<form:select path="delFlag" class="input-xlarge ">
					<form:option value="" label=""/>
					<form:option value="0" label="进行中"/>
					<form:option value="1" label="已归档"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:input path="remarks" htmlEscape="false" maxlength="200" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">描述：</label>
			<div class="controls">
				<form:textarea path="description" htmlEscape="false" rows="4" maxlength="1000" class="input-xxlarge "/>
			</div>
		</div>
		<%-- <div class="form-actions">
		<shiro:hasAnyPermissions name="pro:project:edit,pro:project:create">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
		</shiro:hasAnyPermissions>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div> --%>
	</form:form>
</body>
</html>